Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-model

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-model

ProseMirror's document model

  • 1.24.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
increased by7.33%
Maintainers
1
Weekly downloads
 
Created

What is prosemirror-model?

The prosemirror-model package is a part of the ProseMirror toolkit, which provides a powerful, flexible, and customizable framework for building rich text editors. The prosemirror-model package specifically deals with the document model, which includes defining schemas, creating and manipulating documents, and working with nodes and marks.

What are prosemirror-model's main functionalities?

Defining a Schema

This feature allows you to define a schema for your document. A schema specifies the types of nodes and marks that can appear in the document, as well as their attributes and how they should be serialized to and from DOM.

const { Schema } = require('prosemirror-model');

const mySchema = new Schema({
  nodes: {
    doc: { content: 'block+' },
    paragraph: { content: 'text*', toDOM: () => ['p', 0] },
    text: { inline: true }
  },
  marks: {
    strong: { toDOM: () => ['strong', 0] }
  }
});

Creating a Document

This feature allows you to create a document using the schema you defined. The document is created from a JSON representation that matches the schema.

const { Node } = require('prosemirror-model');

const doc = Node.fromJSON(mySchema, {
  type: 'doc',
  content: [
    { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }
  ]
});

Manipulating Nodes

This feature allows you to manipulate nodes within the document. You can create new nodes, copy existing nodes, and create fragments of nodes.

const { Fragment } = require('prosemirror-model');

const paragraph = mySchema.nodes.paragraph.createAndFill();
const textNode = mySchema.text('New text');
const newParagraph = paragraph.copy(Fragment.from(textNode));

Other packages similar to prosemirror-model

FAQs

Package last updated on 10 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc